<?php

/**
 * This is the model class for table "student".
 *
 * The followings are the available columns in table 'student':
 * @property integer $id
 * @property string $code
 * @property integer $personId
 * @property string $createdAt
 * @property string $updateAt
 * @property integer $createdBy
 * @property integer $updatedBy
 * @property string $status
 * @property integer $isOldAlumnus
 */
class Student extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'student';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('code, personId, createdAt, updateAt, createdBy, updatedBy, status, isOldAlumnus', 'required'),
			array('personId, createdBy, updatedBy, isOldAlumnus', 'numerical', 'integerOnly'=>true),
			array('code, status', 'length', 'max'=>100),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, code, personId, createdAt, updateAt, createdBy, updatedBy, status, isOldAlumnus', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations() {
		$relations = parent::relations();
		$relations['person'] = array(
			self::BELONGS_TO,
			'People',
			'personId',
		);
		return $relations;
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'code' => 'NRP',
			'personId' => 'Person',
			'createdAt' => 'Created At',
			'updateAt' => 'Update At',
			'createdBy' => 'Created By',
			'updatedBy' => 'Updated By',
			'status' => 'Status',
			'isOldAlumnus' => 'Is Old Alumnus',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('code',$this->code,true);
		$criteria->compare('personId',$this->personId);
		$criteria->compare('createdAt',$this->createdAt,true);
		$criteria->compare('updateAt',$this->updateAt,true);
		$criteria->compare('createdBy',$this->createdBy);
		$criteria->compare('updatedBy',$this->updatedBy);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('isOldAlumnus',$this->isOldAlumnus);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Student the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
